package com.zs.games.utils;


import java.util.Arrays;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.lang.Nullable;

/**
 * @author syh
 * @date 2023-06-20
 */
public class StringConvertUtil {

    public static List<Integer> toIntList(String str){
        return Arrays.asList(toIntArray(str));
    }

    public static Integer[] toIntArray(String str){
        if (StringUtils.isBlank(str)) {
            return new Integer[0];
        } else {
            String[] arr = str.split(",");
            Integer[] ints = new Integer[arr.length];

            for(int i = 0; i < arr.length; ++i) {
                Integer v = toInt(arr[i],0);
                ints[i] = v;
            }

            return ints;
        }
    }


    public static Integer toInt(@Nullable final String str, final int defaultValue){
        if (str == null) {
            return defaultValue;
        } else {
            try {
                return Integer.valueOf(str);
            } catch (NumberFormatException var3) {
                return defaultValue;
            }
        }
    }


}
